#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5+10;

#define in read()

typedef struct{int v,nxt;}edge;

int f[MAXN][22],k,n,a[MAXN],h[MAXN],cnt,g[MAXN];
edge e[MAXN<<1];

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1) + (x<<3) + (ch ^ 48);
	return x*sgn;
}

void link(int x,int y){e[++cnt] = (edge){y,h[x]};h[x] = cnt;}

void dfs(int x,int p){
	f[x][0] = a[x];
	for(int i = h[x];i;i = e[i].nxt){
		int y = e[i].v; if(y == p) continue;
		dfs(y,x);
		for(int j = 0;j < k;j++) f[x][j+1] = f[x][j+1] + f[y][j];
	}
}

void dp(int x,int p){
	for(int i = 0;i <= k;i++) g[x] += f[x][i];
	for(int i = h[x];i;i = e[i].nxt){
		int y = e[i].v; if(y == p) continue;
		for(int j = k-1;j >= 0;j--)
			f[y][j+1] += f[x][j] - (j > 0 ? f[y][j-1] : 0);
		dp(y,x);
	}
}
int main (){
	n = in,k = in;
	for(int i = 1;i < n;i++) {
		int x = in,y = in;
		link(x,y);link(y,x);
	}
	for(int i = 1;i <= n;i++) a[i] = in;
	dfs(1,0);
	dp(1,0);
	for(int i = 1;i <= n;i++) printf("%d\n",g[i]);
	return 0;
}
